<template>
  <div class="">
    <a-card :title="title" class="BUCBox">
      <!-- <a-button slot="extra" type='primary' @click="handleQuery">BUC状态查询</a-button> -->
      <a-descriptions size="small" :column="1" bordered style="">
        <a-descriptions-item label="信噪比">
          {{ desData.snrAlarmDesc || '/' }}
        </a-descriptions-item>
        <a-descriptions-item label="频偏">
          {{ desData.freqOffsetAlarmDesc || '/' }}
        </a-descriptions-item>
        <a-descriptions-item label="同步字节错字数">
          {{ desData.syncByteAlarmDesc || '/' }}
        </a-descriptions-item>
      </a-descriptions>
    </a-card>
  </div>
</template>

<script>
import { httpAction, getAction } from '../../api/manage'
export default {
  props: {},
  components: {},

  data() {
    return {
      columns1: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 80,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '告警类型',
          dataIndex: 'monitorType',
          key: 'monitorType'
        },
        {
          title: '告警详情',
          dataIndex: 'alertMessage',
          key: 'alertMessage'
        },
        {
          title: '告警等级',
          dataIndex: 'alertLevel',
          key: 'alertLevel',
          scopedSlots: { customRender: 'alertLevel' }
        }
      ],
      url: {
        recentAlarmStatus: 'dcpr/dcprPassagewayHistoryInfo/getRecentAlarmStatus',
        add: '/plan/qlTestPlan/add'
      },
      // desData: {
      //   // snrAlarmLevel: 'LEVEL_1',
      //   // snrAlarmDesc: '信噪比一级告警',
      //   // freqOffsetAlarmLevel: 'LEVEL_1',
      //   // freqOffsetAlarmDesc: '频偏一级告警',
      //   // syncByteAlarmLevel: 'LEVEL_1',
      //   // syncByteAlarmDesc: '同步字节错字数一级告警'
      // },
      title: '群解调告警信息',
      countDown: '', //倒计时
      timer: null
    }
  },
  computed: {
    desData() {
      return this.$store.state.alarm.desData
    },
    activeInfo() {
      return this.$store.state.alarm.activeInfo
    }
  },
  watch: {},
  created() {},
  mounted() {
    // this.getRecentAlarmStatus()
    // this.startTimer()
    console.log('当前 desData:', this.desData)
    console.log('当前 activeInfo:', this.activeInfo)
    if( !this.desData.snrAlarmDesc && !this.desData.freqOffsetAlarmDesc && !this.desData.syncByteAlarmDesc) {
      this.title = `群解调告警信息（最近10分钟内无告警）`
    }
  },
   destroyed() {
    // this.stopTimer()
  },
  methods: {
    getRecentAlarmStatus() {
      getAction(this.url.recentAlarmStatus).then(res => {
        if (res.success) {
          let str = res.result
          if (typeof str == 'string') {
            this.title = `群解调告警信息  (${str})`
          } else {
            this.desData = res.result
            if (
              this.desData.snrAlarmLevel == 'LEVEL_1' &&
              this.desData.freqOffsetAlarmLevel == 'LEVEL_1' &&
              this.desData.syncByteAlarmLevel == 'LEVEL_1'
            ) {
              this.handleStart()
            }
          }
        }
      })
    },
    //出现三个一级告警，进行自动修复（频偏测试）
    handleStart() {
      let that = this
      let data = {
        endTdh: '34',
        startTdh: '34',
        symbolRate: '900',
        testMode: '导频模式',
        errorSourceData: ''
      }
      httpAction(that.url.add, data, 'post').then(res => {
        if (res.success) {
          that.$message.success(res.message)
          that.loading = false
          that.countDown = 60
          let timerId = setInterval(() => {
            if (that.countDown > 0) {
              that.countDown--
            } else {
              clearInterval(timerId)
            }
          }, 1000)
        } else {
          that.$message.error(res.message)
          that.loading = false
        }
      })
    },
    startTimer() {
      if (this.timer) {
        clearInterval(this.timer)
      }
      this.timer = setInterval(() => {
        this.getRecentAlarmStatus()
      }, 600000)
    },
    stopTimer() {
      clearInterval(this.timer)
    },
  }
}
</script>

<style lang="less" scoped>
.page {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* 一行 2 列 */
  gap: 16px; /* 列间距，按需调 */
}
.item {
  /* 表格宽度自适应 */
  width: 100%;
  border: 1px solid #17dcff;
  padding: 5px;
  // height: 400px;
  .item_table {
    // height: 350px;
  }
}
</style>
